package com.zzyl.controller.customer;

import com.zzyl.base.PageResponse;
import com.zzyl.base.ResponseResult;
import com.zzyl.controller.BaseController;
import com.zzyl.dto.VisitDto;
import com.zzyl.entity.CountByTime;
import com.zzyl.service.CustomerReservationService;
import com.zzyl.utils.UserThreadLocal;
import com.zzyl.vo.VisitVo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/customer/reservation")
@Api(tags = "客户预约管理")
public class CustomerReservationController extends BaseController {

    @Autowired
    CustomerReservationService customerReservationService;

    @GetMapping("/cancelled-count")
    @ApiOperation("查询取消预约数量")
    public ResponseResult<Integer> getCancelledReservationCount() {

        Long userId = UserThreadLocal.getUserId();
        Integer count = customerReservationService.selectCancledReservationCount(userId);
        return success(count);
    }

    @GetMapping("/countByTime")
    @ApiOperation("查询当前时间段剩余预约数量")
    public ResponseResult<CountByTime> getCountByTime(Long time) {
        List<CountByTime> list = customerReservationService.getCountByTime(time);
        return success(list);
    }

    @PostMapping
    @ApiOperation("添加护理项目")
    public ResponseResult add(@RequestBody VisitDto visitDto) {
        customerReservationService.add(visitDto);
        return success();
    }

    @GetMapping("/page")
    @ApiOperation("分页查询预约")
    public ResponseResult<VisitVo> getByPage(
            @RequestParam(defaultValue = "1") Integer pageNum,
            @RequestParam(defaultValue = "10") Integer pageSize,
            @RequestParam(required = false) Integer status) {
        PageResponse<VisitVo> visitVos = customerReservationService.getByPage(pageNum, pageSize, status);
        return success(visitVos);
    }

    @PutMapping("/{id}/cancel")
    @ApiOperation("取消预约")
    public ResponseResult cancel(@PathVariable Long id) {
        customerReservationService.cancel(id);
        return success();
    }
}